package top.itlir.edc.service.impl;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.itlir.edc.dao.SignInfoRepository;
import top.itlir.edc.dao.TransitInfoRepository;
import top.itlir.edc.domain.SignInfo;
import top.itlir.edc.domain.TransitInfo;
import top.itlir.edc.index.WayBillIndexRepository;
import top.itlir.edc.service.ISignInfoService;

@Service
@Transactional
public class SignInfoServiceImpl implements ISignInfoService {

	@Resource
	private SignInfoRepository signInfoRepository;
	
	@Autowired
	private TransitInfoRepository transitInfoRepository;
	
	@Autowired
	private WayBillIndexRepository wayBillIndexRepository;

	@Override
	public void save(SignInfo model, Integer transitInfoId) {
		signInfoRepository.save(model);
		
		TransitInfo transitInfo = transitInfoRepository.findOne(transitInfoId);
		transitInfo.setSignInfo(model);
		
		//3.判断签收类型是否是正常
				if("正常".equals(model.getSignType())){
					//3.1是，将运输配送单状态更新成：正常签收
					//同时更新运单为：3-已签收
					transitInfo.setStatus("正常签收");
					transitInfo.getWayBill().setSignStatus(3);
				} else {
					//3.2否，将运输配送单状态更新成：异常
					//同时更新运单为：4-异常
					transitInfo.setStatus("异常");
					transitInfo.getWayBill().setSignStatus(4);
				}
				//4.更新索引库
				wayBillIndexRepository.save(transitInfo.getWayBill());
		
		
	}

}
